package com.ygxsk.carhome.ui.archive;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.response.ArchiveFileType;
import com.ygxsk.carhome.utils.CommUtils;
import com.zhongjh.progresslibrary.widget.MaskProgressLayout;

import java.util.List;

public class FooterModifyAddSubmitArchiveFileTypeAdapter extends BaseQuickAdapter<ArchiveFileType, BaseViewHolder> {

    //图片的监听逻辑
//    private ArchiveFileAddSubmitActivity.MyFooterMaskProgressLayoutListener insideFooterMaskProgressLayoutListener;

//    public void setMyFooterMaskProgressLayoutListener(ArchiveFileAddSubmitActivity.MyFooterMaskProgressLayoutListener _myFooterMaskProgressLayoutListener) {
//        this.insideFooterMaskProgressLayoutListener = _myFooterMaskProgressLayoutListener;
//    }

    public FooterModifyAddSubmitArchiveFileTypeAdapter(int layoutResId, @Nullable List<ArchiveFileType> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, ArchiveFileType archiveFileTypeItem) {

        if (archiveFileTypeItem != null) {

            //是否是必填项
//                        "fileTypeName":"发票",
//                        "fileType":2,
//                        "required":true

            //标题的名称
            String fileTypeName = archiveFileTypeItem.getFileTypeName();
            //标题的类型
            int fileType = archiveFileTypeItem.getFileType();
            //附件的是否必填 required":true
            boolean required = archiveFileTypeItem.isRequired();

            //单个的事件监听，直接填充为一个对象，再次取出
            ArchiveFileAddSubmitActivity.MyFooterMaskProgressLayoutListener insideFooterMaskProgressLayoutListener = archiveFileTypeItem.getMyFooterMaskProgressLayoutListener();
//            if (myFooterMaskProgressLayoutListener!=null) {
//                myFooterMaskProgressLayoutListener.setModifyArchiveFileType(archiveFileTypeItem);
//            }


            //findviews
            //星星的图片内容
            ImageView imageViewStarRed = (ImageView) baseViewHolder.getView(R.id.imageviewstarred);
            //文字标题内容
            TextView textViewArchiveTypeDes = (TextView) baseViewHolder.getView(R.id.textviewarchivetypedes);
            //九宫格的上传组件
            MaskProgressLayout mplImageListInArchiveType = (MaskProgressLayout) baseViewHolder.findView(R.id.mplimagelistinarchivetype);
            mplImageListInArchiveType.setOperation(true);
            archiveFileTypeItem.setMaskProgressLayoutInItem(mplImageListInArchiveType);


            CommUtils.setText(textViewArchiveTypeDes, fileTypeName);

            if (required) {
                imageViewStarRed.setVisibility(View.VISIBLE);
            } else {
                imageViewStarRed.setVisibility(View.INVISIBLE);
            }

            //先设置这条数据
            if (insideFooterMaskProgressLayoutListener != null) {

//              LogUtils.json(ConstantSign.LOGCAT_NOMAL+"insideFooterMaskProgressLayoutListener.setModifyArchiveFileType-->",archiveFileTypeItem);

                //九宫格监听添加
                if (mplImageListInArchiveType != null) {
                    mplImageListInArchiveType.setMaskProgressLayoutListener(insideFooterMaskProgressLayoutListener);
                    //单个监听器对应的对象
                    insideFooterMaskProgressLayoutListener.setModifyArchiveFileType(archiveFileTypeItem);
                }

            }
        }
    }

}
